function setArrayValue (data, val) {
  for (let item of data) {
    item[val.index] = val.val1
    if (item[val.childName] && item[val.childName].length) {
      setArrayValue(item[val.childName], val)
    }
  }
}
function setAdd (self, data, val) {
  for (let item of data) {
    self.$set(item,val.index, val.val1)
    if (item[val.childName] && item[val.childName].length) {
      setAdd(self,item[val.childName], val)
    }
  }
}
/* 已选商品列表*/
function getValueArray (data, val) {
  /*
    1、如果父级的checked为false,就把父级删掉
    2、如果子集的checked为false，就删掉
  */
  for (let key in data) {
    if( data[key][val.index] == val.status ) {
      data[key] = ''
    } 
    if (data[key][val.childName] && data[key][val.childName].length) {
      getValueArray(data[key][val.childName], val)
    }
  }
} 
function setEmptyArray (data, val) {
  for(var i = 0;i<data.length;i++){
    if (data[i]==''||data[i]==null||typeof(data[i])==undefined) {
      data.splice(i,1);
      i=i-1;
    }
    if(data[i]) {
      if (data[i][val.childName] && data[i][val.childName].length) {
          setEmptyArray(data[i][val.childName], val)
      }
    }
  }
}
function getSelectStatus (data, val) {
  let status = true;
  for (let item of data) {
    if (!item[val.index]) {
      status = false;
    }
    if (item[val.childName] && item[val.childName].length) {
      return  getSelectStatus (item[val.childName], val)
    }
  }
  return status
}
function deleteValueArray (data, val) {
  for (let key in data) {
    let status = true;
    if (data[key][val.childName] && data[key][val.index]) {
      for (let todo in data[key][val.childName]) {
        if(data[key][val.childName][todo][val.index]) {
          data[key][val.childName][todo] = ''
        }else{
          status = false
        }
      }
    }
    if(!data[key][val.index]){
      status = false
    }
    if(status) {
      data[key] = ''
    }
  }
}
function getValueStatus (data, val) {
  for (let key in data) {
    let status = true;
    if (data[key][val.childName] && data[key][val.index]) {
      for (let todo in data[key][val.childName]) {
        if(!data[key][val.childName][todo][val.index]) {
        }else{
          status = false
        }
      }
    }
    if(status) {
      data[key][val.index] = false
    }
  }
}
const columns1= [{
    title: '商品编码',
    key: 'code'
  },{
    title: 'SKU编码',
    key: 'skuCode'
  },{
    title: '商品',
    key: 'name'
  },{
    title: '零售价',
    key: 'price'
  },{
    title: '状态',
    key: 'discount'
  },{
    title: '库存',
    key: 'sale'
  },{
    title: '操作',
    key: 'set'
  }
]
const data1 = []
export {
  data1,
  columns1,
  getValueStatus,
  deleteValueArray,
  getSelectStatus,
  setEmptyArray,
  getValueArray,
  setAdd,
  setArrayValue
} 